<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link type="text/css" rel="stylesheet" href="layui/css/layui.css"/>
		<script type="text/javascript" src="layui/layui.js"></script>
	</head>
	<body>
		<form id="addUser" class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					用户名:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="name" name="name" 
						placeholder="请输入用户名" class="layui-input" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					密码:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="code" name="code" 
						placeholder="请输入密码" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="createUser">提交</button>
				<button type="reset" class="layui-btn" lay-submit>取消</button>
				</div>
			</div>
		</form>
		
		<script>
			layui.use(['form','layer'],function(){
				var form = layui.form,$ = layui.$,layer = layui.layer;
				//23d66d84-fae1-45d5-bd07-b694662fe579
				form.on('submit(createUser)',function(data){
					//layer.msg("提交动作");
					// post把表单数据发送到服务器端
					// 使用序列化的时候 input的name属性当成参数名字  ，值是参数值
					var str = $("#addUser").serialize();
					$.post(
						"http://localhost:8080/xuexizu/UserAdminServlet?reqName=UserAdd",
						str,
						function(res){
							if(res.success){
						   	 //先得到当前iframe层的索引
							var index = parent.layer.getFrameIndex(window.name); 
							//再执行关闭 
							parent.layer.close(index);  
							//关闭父级页面的表格
							parent.layui.table.reload('table');
						   }else{
						   	layer.alert("添加失败");
						   }
						},
						"json"
					)
					
//					$.post(
//						"http://stuapi.ysdjypt.com/api/CreateUser",
//						{"token":"23d66d84-fae1-45d5-bd07-b694662fe579",
//						 "loginName":$("#LoginName").val(),
//						"pwd":$("#password").val(),
//						"email":$("#email").val(),
//						"mtel":$("#phone").val()
//						},
//						function(res){
//							console.log(res);
//						},
//						"json"
//					)
					return false;// 停留在这里
				})
				
			})
			
		</script>
		
	</body>
</html>
